package org.fatmansoft.teach.repository;

import org.fatmansoft.teach.models.DailyActivity;
import org.fatmansoft.teach.models.Student;
import org.fatmansoft.teach.models.StudentDailyActivity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
//中间表数据库操作类
public interface StudentDailyActivityRepository extends JpaRepository<StudentDailyActivity, Integer> {

    @Query(value = "select max(studentDailyActivityId) from StudentDailyActivity ")
    Integer getMaxId();

    void deleteByStudentAndDailyActivity(Student student, DailyActivity dailyActivity);
    StudentDailyActivity findStudentDailyActivityByStudentAndDailyActivity(Student student,DailyActivity dailyActivity);

    @Query(value = "from StudentDailyActivity where ?1 = '' or student.person.name like %?1% or dailyActivity.activityName like %?1%")
    List<StudentDailyActivity> findByStudentDaily(String studentDaily);

    @Query(value = "from StudentDailyActivity where student.person.num like %?1% and (?2 = '' or dailyActivity.activityName like %?2%)")
    List<StudentDailyActivity> findByStudentPersonNumAndDailyActivityActivityName(String studentName, String dailyName);
}
